home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
DIGEST_B
/
DOCUMENT
/
CBROWSER.C
next >
Wrap
Text File
|
1992-03-09
|
7KB
|
279 lines
/****
* CBrowserDoc.c
*
* Document methods for a typical application.
*
* Copyright ⌐ 1990 Symantec Corporation. All rights reserved.
* Copyright ⌐ 1991 Manuel A. PÄrez. All rights reserved.
*
****/
#include "Global.h"
#include "Commands.h"
#include "CApplication.h"
#include "CBartender.h"
#include "CDecorator.h"
#include "CDesktop.h"
#include "CError.h"
#include "CPanorama.h"
#include "CScrollPane.h"
#include "CBrowserDoc.h"
#include "TBUtilities.h"
#include "CWindow.h"
#include <Packages.h>
#include <string.h>
#define WINDBrowser 500 /* Resource ID for WIND template */
/* Commands on the Index Menu */
#define IndexFrom 200
#define IndexDate 201
#define IndexSubject 202
extern CApplication *gApplication; /* The application */
extern CBartender *gBartender; /* The menu handling object */
extern CDecorator *gDecorator; /* Window dressing object */
extern CDesktop *gDesktop; /* The enclosure for all windows */
extern CBureaucrat *gGopher; /* The current boss in the chain of command */
extern OSType gSignature; /* The application's signature */
extern CError *gError; /* The global error handler */
/***
* IBrowserDoc
*
* Does nothing, just calls the CDocument IDocument method
*
***/
void CBrowserDoc::IBrowserDoc(CApplication *aSupervisor, Boolean printable)
{
CDocument::IDocument(aSupervisor, printable);
/* Initialize the default index displayed when the document is first
* created. Ideally, we should read this from a resource.
*/
index_displayed = IndexSubject;
itsListIndex = NULL;
itsMessage = NULL;
}
/***
* NewFile
*
* Empty implementation because we don't allow creation of new documents
***/
void CBrowserDoc::NewFile(void)
{ } // This is correct, see note above.
/***
* OpenFile
*
***/
void CBrowserDoc::OpenFile(SFReply *macSFReply)
{
Str63 theName;
OSErr theError;
BrowserDir dir;
// Copy pascal name to a c name
PtoCstr(macSFReply->fName);
strcpy(dir.fname, (char *)&macSFReply->fName);
CtoPstr(macSFReply->fName);
// Copy the vref too
dir.vRefNum = macSFReply->vRefNum;
// Then let this program do the work
BuildBrowserIndex(&dir); // this could fail
BuildWindow(dir);
itsWindow->SetTitle(macSFReply->fName);
itsWindow->Select(); // Don't forget to make the window active
}
/******************************************************************************
Dispose
******************************************************************************/
void CBrowserDoc::Dispose()
{
itsListIndex->Dispose();
itsMessage->Dispose();
inherited::Dispose();
}
/***
* BuildWindow
*
* This is the auxiliary window-building method that the
* NewFile() and OpenFile() methods use to create a window.
*
* In this implementation, the argument is the data to display.
*
***/
void CBrowserDoc::BuildWindow (BrowserDir dir)
{
CScrollPane *theScrollPane;
CScrollPane *the2ndScrollPane;
LongRect theAperture;
short w;
// const to help us understand the code
#define scrollerHeight 120
#define listHeight (scrollerHeight-16)
#define contentsVLoc (scrollerHeight+1)
/** First create the window and initialize it. **/
itsWindow = new(CWindow);
itsWindow->IWindow(WINDBrowser, FALSE, gDesktop, this);
itsWindow->GetAperture(&theAperture);
w = theAperture.bottom - theAperture.top - scrollerHeight;
/** Create a scroll pane for the index field **/
theScrollPane = new(CScrollPane);
theScrollPane->IScrollPane(itsWindow, this, 10, scrollerHeight, 0, 0,
sizELASTIC, sizFIXEDSTICKY,
TRUE, TRUE, FALSE);
theScrollPane->FitToEnclFrame(TRUE, FALSE);
/**
** itsMainPane is the document's focus
** of attention. Some of the standard
** classes (particularly CPrinter) rely
** on itsMainPane pointing to the main
** pane of your window.
**
** itsGopher specifies which object
** should become the gopher when the document
** becomes active. By default
** the document becomes the gopher. It╒s
** likely that your main pane handles commands
** so you╒ll almost always want to set itsGopher
** to point to the same object as itsMainPane.
**
**/
/** Create a DisplayIndex (top of the window) */
itsListIndex = new(CDisplayIndex);
itsGopher = itsListIndex;
itsListIndex->IDisplayIndex(theScrollPane, this, 0, listHeight, dir, index_displayed);
theScrollPane->InstallPanorama(itsListIndex);
//**
// Build the contents of the message display
//**
the2ndScrollPane = new(CScrollPane);
the2ndScrollPane->IScrollPane(itsWindow, this,
10, w, // sizes
0, contentsVLoc, // locations
sizELASTIC, sizELASTIC, // sizes types
TRUE, TRUE, TRUE); // horiz, vert, and size box
the2ndScrollPane->FitToEnclFrame(TRUE, FALSE); // horiz, vert
itsMessage = new(CDisplayText);
itsMessage->IDisplayText(the2ndScrollPane, this, contentsVLoc, 1);
the2ndScrollPane->InstallPanorama(itsMessage);
// itsMainPane is used for printing, so set the message (not the index)
// field as the main pane.
itsMainPane = itsMessage;
//
// Establish dependency between the two displays, by making
// the message display be dependent upon the selection on
// the index display
//
itsMessage->DependUpon(itsListIndex);
gDecorator->PlaceNewWindow(itsWindow);
}
/***
* DoCommand {OVERRIDE}
*
* Execute a command
*
***/
void CBrowserDoc::DoCommand(long theCommand)
{
long selLine;
switch (theCommand) {
case IndexFrom:
case IndexDate:
case IndexSubject:
// Store index in an instance variable
index_displayed = theCommand;
// Save the currently selected line
selLine = itsListIndex->GetSelectedLine();
// Set the index in the index display
itsListIndex->SetIndex(theCommand);
// Setting the selected line back to what it was
itsListIndex->SetSelectedLine(selLine, true);
break;
default:
inherited::DoCommand(theCommand);
break;
}
}
/***
* UpdateMenus {OVERRIDE}
*
* Enable all Index items, and place a check mark next to the current
* one
*
***/
void CBrowserDoc::UpdateMenus()
{
inherited::UpdateMenus();
gBartender->EnableCmd(IndexFrom);
gBartender->EnableCmd(IndexDate);
gBartender->EnableCmd(IndexSubject);
gBartender->CheckMarkCmd(IndexFrom, index_displayed == IndexFrom);
gBartender->CheckMarkCmd(IndexDate, index_displayed == IndexDate);
gBartender->CheckMarkCmd(IndexSubject, index_displayed == IndexSubject);
}
/***
* ConfirmClose {OVERRIDE}
*
* The text edit panes make this document think that it has been modified.
* Since we don't support saving digest browsers, lets just fake it, and
* make it behave as if the user said it was ok to close the document
* without saving it.
*
* There might be a better way around this. But this works nice.
***/
Boolean CBrowserDoc::ConfirmClose(Boolean quitting)
{
Boolean okToClose = TRUE;
return(okToClose);
}